const net = require('net');
const DataManage = require('./SocketDataManage');
let port = 8002;
let server = net.createServer();
server.listen(port,function () {
    console.log(`open port ${port}`);
})
server.on('connection', function (socket) {
    let dataManage = new DataManage(9, 1);
    dataManage.getNextSize = function (data) {
        let s = data.toString();
        return parseInt(s) + 1;
    };
    dataManage.handleData = function (data) {
        let s = data.toString();
        console.log(s);
    };
    socket.on('data', function (data) {
        try {
            dataManage.putData(data)
        } catch (e) {
            socket.end();
            console.log(e);
        }
    })
    socket.on('error', function (e) {
        socket.end();
        console.log(e);

    })
})